<?php
namespace app\web\admin;

use app\common\builder\ZBuilder;
use app\web\model\RechargeStrategy as myModel;
use app\web\model\CouponType;


/**
 * 充值策略
 * @package
 */
class Rechargestrategy extends Base 
{
    public function index(){
        $map = $this->getMap();
        $list = myModel::where($map)
                        ->order($this->getOrder('recharge_money'))
                        ->paginate();
        $fields = [
            ['hidden', 'id'],
            ['text', 'strategy_name', '策略名称', '必填'],
            ['text', 'recharge_money', '充值金额', '必填'],
            ['text', 'give_money', '赠送金额', '必填',0],
            ['number', 'sort', '排序', '必填',100],
            ['radio', 'status', '状态', '', ['禁用', '启用'], 1],
        ];
        return ZBuilder::make('table')
            ->setTableName('recharge_strategy')
            ->setSearch(['strategy_name' => '策略名称']) // 设置搜索参数
            ->autoAdd($fields,'recharge_strategy','Rechargestrategy',true)
            ->autoEdit($fields,'recharge_strategy','Rechargestrategy',true)
            ->addTopButtons(['disable','enable','delete'=>['data-tips' => '删除了就无法恢复了']])
            ->addColumns([
                ['id', 'ID'],
                ['strategy_name', '策略名称'],
                ['recharge_money', '充值金额'],
                ['give_money','赠送金额'],
                ['update_time', '更新时间', 'datetime'],
                ['status', '状态', 'switch'],
                ['right_button', '操作', 'btn'],
            ])
            ->addOrder('recharge_money,give_money')
            ->addRightButtons(['delete' => ['data-tips' => '删除后无法恢复。']])
            ->setRowList($list)
            ->fetch();
    }
   /**
     * 删除
     * [delete description]
     * @param  array  $record [description]
     * @return [type]         [description]
     */
    public function delete($record = [])
    {
        $ids   = $this->request->isPost() ? input('post.ids/a') : input('param.ids');
        $ids   = (array)$ids;
        myModel::destroy($ids);
        $this->success('操作成功');
    }
}